package com.marveal.rabbit.producer.broker;

import com.marveal.rabbit.api.Message;

import java.util.ArrayList;
import java.util.List;

public class MessageHolder {

    private final List<Message> messages = new ArrayList<>();

    private static final ThreadLocal<MessageHolder> holder = ThreadLocal.withInitial(MessageHolder::new);

    public static void add(Message message) {
        holder.get().messages.add(message);
    }

    public static List<Message> clear() {
        List<Message> result = new ArrayList<>(holder.get().messages);
        holder.get().messages.clear();
        return result;
    }

}
